@page "/LimitRange"
@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using k8s.Models
@inherits BlazorApp.Pages.Common.TableBase<V1LimitRange>
@if (TableData.PagedItems != null)
{
    <HTable Class="wideTable">
        <HTr>
            <HTd >
                <SearchToolBar Title=@L["LimitRange"] Count="@TableData.Total"
                               OnItemDeletedCallback="@(async () => await InvokeAsync(StateHasChanged))"
                               OnSelectedItemCloseClicked="@TableData.RemoveSelection"
                               OnRemoveAllClicked="@TableData.RemoveAllSelection" TableData="@TableData"
                               OnSearch="OnSearchHandler" TItem="V1LimitRange"
                               OnNsSelected="OnNsSelectedHandler">
                </SearchToolBar>
            </HTd>
        </HTr>
        <HTr>
            <HTd >
                <Table TItem="V1LimitRange"
                       DataSource="@TableData.PagedItems"
                       Size=@TableSize.Small Bordered="true"
                       Total="TableData.Total"
                       @bind-PageIndex="TableData.PageIndex"
                       @bind-PageSize="TableData.PageSize"
                       @bind-SelectedRows="TableData.SelectedRows"
                       Loading="TableData.Loading"
                       OnChange="OnPageChangeHandler">
                    <Selection Key="@(context.Name())"/>
                    <AntDesign.Column Field="@context.Name()" Title=@L["Name"]>
                        <Button OnClick="@(() => OnItemNameClick(context))" Type="@ButtonType.Link">@context.Name()</Button>
                    </AntDesign.Column>
                    <AntDesign.Column Field="@context.Namespace()" Title=@L["Namespace"] Width="110px"/>
                    <AntDesign.Column Title=@L["Type"] TData="string">
                        @foreach (var type in context.Spec.Limits.Where(x => x != null).Select(x => x.Type))
                        {
                            <ColorfulTag>@type</ColorfulTag>
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Default Limits"] TData="string">
                        @foreach (var d in context.Spec.Limits.Where(x => x != null).Select(x => x.DefaultProperty))
                        {
                            if (d is { Count: > 0 })
                            {
                                foreach (var (key, value) in d)
                                {
                                    <ColorfulTag>@key=@value</ColorfulTag>
                                }
                            }
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Default Request"] TData="string">
                        @foreach (var d in context.Spec.Limits.Where(x => x != null).Select(x => x.DefaultRequest))
                        {
                            if (d is { Count: > 0 })
                            {
                                foreach (var (key, value) in d)
                                {
                                    <ColorfulTag>@key=@value</ColorfulTag>
                                }
                            }
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["MaxLimitRequestRatio"] TData="string">
                        @foreach (var d in context.Spec.Limits.Where(x => x != null).Select(x => x.MaxLimitRequestRatio))
                        {
                            if (d is { Count: > 0 })
                            {
                                foreach (var (key, value) in d)
                                {
                                    <ColorfulTag>@key=@value</ColorfulTag>
                                }
                            }
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Min"] TData="string">
                        @foreach (var min in context.Spec.Limits.Where(x => x != null).Select(x => x.Min))
                        {
                            if (min is { Count: > 0 })
                            {
                                foreach (var (key, value) in min)
                                {
                                    <ColorfulTag>@key=@value</ColorfulTag>
                                }
                            }
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Max"] TData="string">
                        @foreach (var max in context.Spec.Limits.Where(x => x != null).Select(x => x.Max))
                        {
                            if (max is { Count: > 0 })
                            {
                                foreach (var (key, value) in max)
                                {
                                    <ColorfulTag>@key=@value</ColorfulTag>
                                }
                            }
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Age"] TData="string" Width="100px">
                        <AgeView Age="@context.CreationTimestamp()"></AgeView>
                    </AntDesign.Column>
                    <ActionColumn Title=@L["Action"] Width="100px">
                        <LimitRangeAction Item="@context"></LimitRangeAction>
                    </ActionColumn>
                </Table>

            </HTd>
        </HTr>
    </HTable>
    <ResourceWatcher OnResourceChanged="OnResourceChanged" T="V1LimitRange"></ResourceWatcher>
}
